const http = require('http');
const fs = require('fs');
const path = require('path');

var arr = process.argv;

http.createServer((req, res) => {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    })
    var filePath = path.join(__dirname, './fileReader3.js');
    if (arr[2]) {
        var filePath1 = path.join(__dirname, arr[2]);
        if (fs.existsSync(filePath1)) {
            var readable = fs.createReadStream(filePath1);
            readable.pipe(res);
        } else {
            console.log('该路径不存在');
        }

    } else {
        var readable1 = fs.createReadStream(filePath);
        readable1.pipe(res);
    }


}).listen(8081);
console.log('server listening on port');